<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DECP后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" >
    <link href="/iconfont/style.css" type="text/css" rel="stylesheet">
</head>
<body style="padding: 10px;">

<form class="layui-form" lay-filter="formModify" action="sysUser/modify" method="get">
    <div class="layui-form-item">
        <label class="layui-form-label">用户ID</label>
        <div class="layui-input-block">
            <input type="text" name="userId" id="userId" lay-verify="title" autocomplete="off" readonly="readonly"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">登录账号</label>
        <div class="layui-input-block">
            <input type="text" name="userCode" lay-verify="required" autocomplete="off"
                   placeholder="请输入登录账号" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">用户昵称</label>
        <div class="layui-input-block">
            <input type="text" name="userName" id="userName" lay-verify="title" autocomplete="off" placeholder="请输入用户昵称"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">用户性别</label>
        <div class="layui-input-block">
            <input type="radio" name="userSex" value="1" title="男" id="man" checked="">
            <input type="radio" name="userSex" value="2" title="女" id="woman">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="tel" name="userPhone" id="userPhone" lay-verify="required|phone" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">用户邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="userEmail" id="userEmail" lay-verify="email" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">用户状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="userActivate" id="userActivate"  lay-skin="switch" lay-text="激活|禁用" >
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit="demo1" lay-filter="demo1">立即提交</button>
            <button type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="/js/layui/layui.all.js"></script>


<script>
    layui.use(['form', 'layedit', 'jquery'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , $ = layui.jquery;

        form.verify({
            userCode: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
        });

//监听指定开关
        form.on('switch(userActivate)', function (obj) {
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
        });

        $("#reset").on('click',function () {
            location.reload();
        });


        var data = top.layerFrameConfig.iframeUserModify.data;

        form.val("formModify", {
            userId: data.userId,
            userCode: data.userCode,
            userPassword: data.userPassword,
            userName: data.userName,
            userSex: data.userSex,
            userPhone: data.userPhone,
            userEmail: data.userEmail,
            userActivate: data.userActivate,
        });




        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(demo1)', function (res) {
//            res.field.userId = data.userId;
            console.log(res.field.userId);
            console.log(res.field.userActivate);
            console.log("最终提交的信息==" + JSON.stringify(res.field) + "===" + res.field.userActivate=="on");
            $.ajax({
                url:'sysUser/modify',
                type:'get',
                dataType:'json',
                data:{
                    userId:res.field.userId,
                    userCode:res.field.userCode,
                    userActivate:res.field.userActivate=='on'?1:0,
                    userEmail:res.field.userEmail,
                    userName:res.field.userName,
                    userSex:res.field.userSex,
                    userPhone:res.field.userPhone
                },
                success:function (sub) {
                    if (sub.errorCode = "0") {
                        parent.layer.close(top.layerFrameConfig.iframeUserModify.layer_index);
                        parent.layer.msg('修改成功');
                    } else {
                        parent.layer.close(top.layerFrameConfig.iframeUserModify.layer_index);
                        parent.layer.msg('修改失败');
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
